package com.example.demo.security.service;

import com.example.demo.security.bean.SecurityResourceBean;
import com.example.demo.security.bean.SecurityRoleBean;
import com.example.demo.security.bean.SecurityRoleResourceBean;
import com.example.demo.security.repository.SecurityRoleResourceRepository;
import com.example.demo.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class SecurityRoleResourceService extends BaseService<SecurityRoleResourceBean,SecurityRoleResourceRepository> {

    public Set<SecurityRoleResourceBean> createRoleResourceBean(List<SecurityResourceBean> list){
        return list.parallelStream().map(b->{
            SecurityRoleResourceBean bean = new SecurityRoleResourceBean();
            bean.setResource(b);
            return bean;
        }).collect(Collectors.toSet());
    }

    public List<String> getResource(SecurityRoleBean bean) {
        return bean.getRoleResourceBeanSet().parallelStream().map(b->String.valueOf(b.getResource().getId())).collect(Collectors.toList());
    }
}
